from typing import *
from math import inf


class Solution:

    def minimumSeconds(self, nums: List[int]) -> int:
        h, n = {}, len(nums)
        for i, v in enumerate(nums):
            if v not in h:
                h[v] = [i, i, i]  # 第一次出现，上一次出现，最大距离
            else:
                h[v][2] = max(h[v][2], i - h[v][1])
                h[v][1] = i
        mn = inf
        for k, v in h.items():
            mn = min(mn, max(v[2], v[0] - v[1] + n))
        return mn // 2